﻿Imports System.Data
Imports System.Data.SqlClient
Imports CondorTravel.BE
Imports CondorTravelUTIL.DL



Public Class ProveedorDALC


    Public Function ValidarProveedor(ByVal objLisProveedorBE As ProveedorBE, ByRef bExito As Boolean, ByRef sMensaje As String) As List(Of ProveedorBE)

        Dim sqlListar As String
        Dim objListaProveedor As New List(Of ProveedorBE)
        Dim objProveedorBE As ProveedorBE = Nothing
        Dim arrSqlParameter(0) As SqlParameter
        Dim ds As DataSet
        Dim dt As DataTable

        Dim objDatos As New AccesoDatos()

        Dim intI As Integer = 0

        Try

            sqlListar = "SP_ValidarProveedorList"

            arrSqlParameter(0) = New SqlParameter("@CODIGO", System.Data.SqlDbType.Int)
            arrSqlParameter(0).Value = objLisProveedorBE.Codigo

            ds = objDatos.DevuelveDataSet(sqlListar, bExito, sMensaje, arrSqlParameter)
            dt = ds.Tables(0)


            objListaProveedor = New List(Of ProveedorBE)()

            If dt.Rows.Count > 0 Then

                While intI < dt.Rows.Count
                    objProveedorBE = New ProveedorBE()
                    objProveedorBE.Codigo = dt.Rows(intI).ItemArray(0).ToString
                    intI = intI + 1

                    objListaProveedor.Add(objProveedorBE)
                End While
            End If

        Catch ex As Exception
            MsgBox(ex.Message, vbCritical, "Error del sistema")
            Return Nothing
            Exit Function
        End Try


        Return objListaProveedor

    End Function


    Public Function ListarProveedores(ByVal objLisProveedorBE As ProveedorBE, ByRef bExito As Boolean, ByRef sMensaje As String) As List(Of ProveedorBE)

        Dim sqlListar As String
        Dim objListaProveedor As New List(Of ProveedorBE)
        Dim objProveedorBE As ProveedorBE = Nothing
        Dim arrSqlParameter(1) As SqlParameter
        Dim ds As DataSet
        Dim dt As DataTable

        Dim objDatos As New AccesoDatos()

        Dim intI As Integer = 0

        Try

            sqlListar = "SP_ProveedorList"

            arrSqlParameter(0) = New SqlParameter("@T_RAZON_SOCIAL", System.Data.SqlDbType.VarChar)
            arrSqlParameter(0).Value = objLisProveedorBE.RazonSocial

            arrSqlParameter(1) = New SqlParameter("@T_RUC_EMP", System.Data.SqlDbType.VarChar)
            arrSqlParameter(1).Value = objLisProveedorBE.Ruc

            ds = objDatos.DevuelveDataSet(sqlListar, bExito, sMensaje, arrSqlParameter)
            dt = ds.Tables(0)


            objListaProveedor = New List(Of ProveedorBE)()

            If dt.Rows.Count > 0 Then

                While intI < dt.Rows.Count
                    objProveedorBE = New ProveedorBE()
                    objProveedorBE.Codigo = dt.Rows(intI).ItemArray(0).ToString
                    objProveedorBE.RazonSocial = dt.Rows(intI).ItemArray(1).ToString
                    objProveedorBE.Ruc = dt.Rows(intI).ItemArray(2).ToString

                    intI = intI + 1

                    objListaProveedor.Add(objProveedorBE)
                End While
            End If

        Catch ex As Exception
            MsgBox(ex.Message, vbCritical, "Error del sistema")
            Return Nothing
            Exit Function
        End Try


        Return objListaProveedor

    End Function


    Public Function ListarProveedorSel() As List(Of ProveedorBE)


        Dim sqlProveedorListar As String
        Dim listProveedorBE As List(Of ProveedorBE) = Nothing
        Dim objProveedorBE As ProveedorBE = Nothing
        Dim ds As DataSet
        Dim dt As DataTable

        Try

            sqlProveedorListar = "SP_SelProveedorList"

            Dim oDatos As New AccesoDatos()
            Dim bExito As Boolean
            Dim sMensaje As String = String.Empty
            Dim i As Integer = 0

            ds = oDatos.DevuelveDataSet(sqlProveedorListar, bExito, sMensaje, Nothing)
            dt = ds.Tables(0)


            listProveedorBE = New List(Of ProveedorBE)()

            If dt.Rows.Count > 0 Then

                While i < dt.Rows.Count
                    objProveedorBE = New ProveedorBE()
                    objProveedorBE.Codigo = CType(dt.Rows(i).ItemArray(0).ToString, Integer)
                    objProveedorBE.RazonSocial = dt.Rows(i).ItemArray(1).ToString
                    i = i + 1

                    listProveedorBE.Add(objProveedorBE)
                End While
            End If

        Catch ex As Exception
            Throw
        End Try

        Return listProveedorBE

    End Function

    Public Function ListarProveedoresxServicio(ByVal objServicioBE As ServicioBE, ByRef bExito As Boolean, ByRef sMensaje As String) As List(Of ProveedorBE)



        Dim sqlListar As String
        Dim objListaProveedor As New List(Of ProveedorBE)
        Dim objProveedorBE As ProveedorBE = Nothing

        Dim arrSqlParameter(0) As SqlParameter
        Dim ds As DataSet
        Dim dt As DataTable

        Dim objDatos As New AccesoDatos()

        Dim intI As Integer = 0

        Try

            sqlListar = "SP_ProveedorxServicioList"

            arrSqlParameter(0) = New SqlParameter("@CODSER", System.Data.SqlDbType.Int)
            arrSqlParameter(0).Value = objServicioBE.CodServicio

            ds = objDatos.DevuelveDataSet(sqlListar, bExito, sMensaje, arrSqlParameter)
            dt = ds.Tables(0)

            objListaProveedor = New List(Of ProveedorBE)()

            If dt.Rows.Count > 0 Then

                While intI < dt.Rows.Count
                    objProveedorBE = New ProveedorBE()
                    objProveedorBE.Codigo = dt.Rows(intI).ItemArray(0).ToString
                    objProveedorBE.RazonSocial = dt.Rows(intI).ItemArray(1).ToString
                    intI = intI + 1
                    objListaProveedor.Add(objProveedorBE)
                End While
            End If


        Catch ex As Exception
            MsgBox(ex.Message, vbCritical, "Error del sistema")
            Return Nothing
            Exit Function
        End Try


        Return objListaProveedor

    End Function


  
End Class
